
/**
 *
 */
package com.bigknow.appstore.web.framework.service;

import com.bigknow.appstore.web.framework.entity.IEntity;
import com.bigknow.appstore.web.framework.vo.Page;

import java.util.List;


/**
 *
 * @param <T>
 */
public interface ICRUDService<T extends IEntity> extends IService {
    /**
     * Find first record by Id
     *
     * @param id
     * @return
     */
    public T get(String id);

    /**
     * Condition search.
     *
     * @param t
     * @return
     */
    public List<T> find(T t);

    /**
     * Condition search.
     *
     * @param t
     * @param limit
     * @return
     */
    public List<T> find(T t,int limit);

    /**
     * Condition search and get first one.
     * @param t
     * @return
     */
    public T findFirst(T t);

    /**
     * Find records for pagination
     *
     * @param t         condition object
     * @param pageIndex current page index
     * @param pageSize  Record size for one page
     * @return current page records
     */
    public Page<T> find(T t, int pageIndex, int pageSize);

    /**
     * Use fuzzy field for fuzzy condition searching.
     *
     * @param t fuzzy condition object
     * @return
     */
    public List<T> findWithFuzzy(T t);

    /**
     * Use fuzzy field for fuzzy condition searching in pagination.
     *
     * @param t         fuzzy condition object
     * @param pageIndex current page index
     * @param pageSize  record size for one page
     * @return current page records
     */
    public Page<T> findWithFuzzy(T t, int pageIndex, int pageSize);

    /**
     * Find all records
     *
     * @return
     */
    public List<T> findAll();

    /**
     *
     * @return
     */
    public List<T> findLimit(int limit);

    /**
     * Save record.If database have same Id record,then update this record.
     *
     * @param t
     */
    public int save(T t);

    /**
     * Insert record.Reject when record's Id is null.
     *
     * @param t
     * @return
     */
    public int insert(T t);

    /**
     * Update record.
     *
     * @param t
     * @return Update success record count.If 0 is not update
     */
    public int update(T t);

    /**
     * Delete record by Id.
     *
     * @param id
     * @return
     */
    public int delete(String id);

    /**
     * Return total count of this entity.
     *
     * @return
     */
    public long getCount();

}
